package com.xckj.cycling.utils;

import android.content.Context;
import android.os.SystemClock;

import com.xckj.cycling.context.AppContext;
import com.xckj.cycling.global.Constant;

import java.util.Locale;

/**
 * @Author: ChenYao
 * @Describe: Android工具类
 * @Date: 2023/3/5 22:02
 */
public class AndroidUtil {
    private static long lastClickTime;
    private static final int CLICK_REPEAT_TIME = 400;

    /**
     * 判断用户连续点击按钮间隔
     *
     * @return 是否连续点击
     */
    public static boolean isFastDoubleClick() {
        long time = SystemClock.uptimeMillis();
        if (time - lastClickTime < CLICK_REPEAT_TIME) {
            return true;
        }
        lastClickTime = time;
        return false;
    }

    /**
     * 是否是中文
     *
     * @param context 上下文对象
     * @return true 中文 false 不是中文
     */
    public static boolean isChinese(Context context) {
        Locale locale = context.getResources().getConfiguration().locale;
        String language = locale.getLanguage();
        return Constant.CHINESE.equals(language);
    }

    /**
     * 是否是中文
     *
     * @return true 中文 false 英文
     */
    public static String isChinese() {
        if (isChinese(AppContext.globalContext())) {
            return "zh";
        } else {
            return "en";
        }
    }
}
